﻿//
// Created by francklinson on 2021/3/16.
//
#include <iostream>

using namespace std;

double add(double x, double y)
{
    return x + y;
}

double mul(double x, double y)
{
    return x * y;
}

double square(double x, double y)
{
    return x * x + y * y;
}

double calculate(double x, double y, double (*function)(double, double))
{
    return (*function)(x, y); // function为函数指针
}


int main()
{
    double (*pf[3])(double, double) = {add, mul, square}; //pf是一个函数指针数组 每一个元素都是一个函数指针
    double a, b;
    cout << "Enter 2 numbers:" << endl;
    while (cin >> a >> b)
    {
        for (auto &i : pf)
        {
            cout << calculate(a, b, i) << endl;
        }
        cout << "Enter 2 numbers:" << endl;
    }
    return 0;
}